<%@page import="com.hamizhong.iflowers.utils.MyConstants"%>
<%@page import="com.hamizhong.iflowers.utils.MyColumnIndicator"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@include file="../../common/common_admin.jsp" %>
<title>订单管理</title>
</head>

<script type="text/javascript">
	$(function() {
		initOrderList(1);
	});
	
	function initOrderList(pageNum) {
		var orderState = $('#orderStateSel').val();
		$.ajax({
			url: '<%=request.getContextPath() %>/admin/ajaxQueryOrdersByState.action',
			data: {
				"orderState": orderState,
				"pageNum": pageNum
			},
			type: 'post',
			async: true,
			dataType: 'json',
			success: function (res) {
				var rs = res.result;
				var totalCnt = res.totalCnt;
				var totalPageCnt = res.totalPageCnt;
				var pageNum = res.pageNum;
				if(rs != 0) {
					var msg = res.msg;
					alert(msg);
					return;
				}else {
					var data = res.data;
					var dataHtml = '';
					if(data.length == 0) {
						dataHtml += '当前状态下暂时没有您的订单！';
					}else {
						dataHtml += 
						'<table width="100%" border="1px">'+
							'<thead>'+
								'<tr style="font-weight: bold;">'+
									'<td width="60">商品图片</td>'+
									'<td width="100">订单编号</td>'+
									'<td width="200">商品名称</td>'+
									'<td width="60">数量</td>'+
									'<td width="60">总价</td>'+
									'<td width="60">收件人</td>'+
									'<td width="60">订单状态</td>'+
									'<td width="100">创建时间</td>'+
									'<td width="100">更新时间</td>'+
									'<td width="60">操作</td>'+
								'</tr>'+
							'</thead>';
						for(var i=0;i<data.length;i++) {
							dataHtml += 
							'<tr>'+
								'<td><div style="width: 60px;height: 60px;"><a target="_blank" href="<%=request.getContextPath() %>/goodsItem.action?goodsId='+data[i].goodsId+'"><img width="56px" height="56px"  style="margin: 2px;" alt="" src="<%=request.getContextPath() %>/'+data[i].goodsPictureS+'" /></a></div></td>'+
								'<td style="font-size: 10px;">'+data[i].orderNum+'</td>'+
								'<td><a target="_blank" href="<%=request.getContextPath() %>/goodsItem.action?goodsId='+data[i].goodsId+'">'+data[i].goodsName+'</a></td>'+
								'<td>'+data[i].goodsCnt+'</td>'+
								'<td>'+data[i].orderPrice+'</td>'+
								'<td>'+data[i].consigneeName+'</td>'+
								'<td>'+data[i].orderStateStr+'</td>'+
								'<td>'+data[i].createDate+'</td>'+
								'<td>'+data[i].doneDate+'</td>';
							if(data[i].orderState == '<%=MyColumnIndicator.O_ST_A%>') {
								dataHtml += 
								'<td><a href="javascript: void(0);" onclick="alertOrderDetailWindow('+data[i].orderId+')">去发货</a></td>';
							}else if(data[i].orderState == '<%=MyColumnIndicator.O_ST_BACK_A%>') {
								dataHtml += 
								'<td><a href="javascript: void(0);" onclick="alertOrderDetailWindow('+data[i].orderId+')">去确认退订</a></td>';
							}else {
								dataHtml += 
								'<td><a href="javascript: void(0);" onclick="alertOrderDetailWindow('+data[i].orderId+')">查看</a></td>';
							}
							dataHtml += 
							'</tr>';
						}
						dataHtml += '</table>';
					}
					$('#itemListDiv').html(dataHtml);	
					
					/*分页*/
					var pagingHtmlStr = queryPagingModule(pageNum,totalPageCnt,totalCnt);
					$('#pagingDiv').html(pagingHtmlStr);
				}
			}
		});
	}
	
	//跳转到指定页码
	function goTargetPageNum(targetPageNum) {
		initOrderList(targetPageNum);
	}
	function checkToTargetPage(totalPageNum) {
		var inputPageNum = $('#targetPageInput').val();
		//判断是否为空--是否为整数--是否为正数--是否为有效页数内的正整数
		if( isNaN(inputPageNum) || (parseInt(inputPageNum) != inputPageNum) || 
				(Math.abs(parseInt(inputPageNum)) != parseInt(inputPageNum)) ||  (inputPageNum > totalPageNum) || (inputPageNum < 1 )) {
			alert("请输入查询范围内的正整数页码！");
			return;
		}else {
			goTargetPageNum(inputPageNum);
		}
	}
	
	function alertOrderDetailWindow(orderId) {
		//vReturnValue = window.showModelessDialog(sURL,[vArguments],[sFeatures]);
		//vArguments:可选参数，类型：变体。用来向对话框传递参数。传递的参数类型不限，包括数组等
		//var obj = new Object(); obj.name="testname";
		//对话框通过window.dialogArguments来取得传递进来的参数。
	    var retValue;
		var pageURL = '<%=request.getContextPath() %>/admin/orderDetail.action?orderId='+orderId+'&random='+Math.random();
		var dialogWidth = 800;
		var dialogHeight = 600;
		var dialogTop = (screen.height - dialogHeight)/2;
		var dialogLeft = (screen.width - dialogWidth)/2;
		var params = 'dialogTop:'+dialogTop+'px;dialogLeft:'+dialogLeft+';dialogWidth:'+dialogWidth+'px;dialogHeight:'+dialogHeight+'px;help:no;unadorned:no;resizable:no;status:no;';
		retValue = window.showModalDialog(pageURL,window,params);
	    //弹出窗口通过：window.returnValue="xxx"; 返回值。也可以是对象
	    //alert(retValue);
	}
	
</script>

<body>
	<div class="displayPageHeader">当前位置：订单管理 >> 订单管理</div>
	<div class="pageDiv">
		<div class="pageHeadDiv">订单搜索</font></div>
		<div class="infoDiv">
			<form id="itemForm" action="#none" method="post">
				<table>
					<tr>
						<td>&nbsp;&nbsp;订单类型&nbsp;&nbsp;</td>
						<td>
							<select id="orderStateSel" onchange="initOrderList(1)">
								<option selected="selected" value="<%=MyColumnIndicator.O_ST_ALL%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_ALL) %></option>
								<option value="<%=MyColumnIndicator.O_ST_E%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_E) %></option>
								<option value="<%=MyColumnIndicator.O_ST_A%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_A) %></option>
								<option value="<%=MyColumnIndicator.O_ST_B%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_B) %></option>
								<option value="<%=MyColumnIndicator.O_ST_C%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_C) %></option>
								<option value="<%=MyColumnIndicator.O_ST_D%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_D) %></option>
								<option value="<%=MyColumnIndicator.O_ST_BACK_A%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_BACK_A) %></option>
								<option value="<%=MyColumnIndicator.O_ST_BACK_C%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_BACK_C) %></option>
								<option value="<%=MyColumnIndicator.O_ST_BACK_B%>"><%=MyColumnIndicator.O_ST_DESC_MAP.get(MyColumnIndicator.O_ST_BACK_B) %></option>
							</select>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<div class="pageDiv">
		<div class="pageHeadDiv">订单列表</div>
		<div class="infoDiv">
			<div id="itemListDiv" class="itemListDiv">
				
			</div>
			<div class="margin_5"></div>
			<div id="pagingDiv" style="border: 1px solid #CCC;width: 100%;height: 25px;line-height: 25px;text-align: left;">
				
			</div>
		</div>
	</div>
	<div class="margin_50"></div>
</body>
</html>